package com.wenli.graduate2022.wenliGreenShop.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * @author HuangHai
 * @date 2021/10/5 14:17
 */
@Data
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler" })
public class Product implements Serializable {
    private Integer productId;
    private String productName;
    private String productTitle;  //标题
    private Double productPrice; //  原价
    private Double productSalePrice;    //促销价格
    //@JsonFormat(timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")//前端传入日期字符串【带有时分秒】，bean类接收JSON转换异常的解决方案
    //@JSONField(format="yyyy-MM-dd HH:mm:ss")
    @Getter(AccessLevel.NONE)
    private Date productCreateDate;  //创建日期
    private Category productCategory;  // 所属种类
    private Byte productIsEnabled;  // 状态，0为出售状态，1为停售状态，2为促销状态


    public String getProductCreateDate() {
        if(productCreateDate != null){
            SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.UK);
            return time.format(productCreateDate);
        }
        return null;
    }
}
